// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ServerViewModel.cs" company="Akzente.IT">
//   (c) 2012 Akzente.IT
// </copyright>
// <summary>
//   The server view model.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace AkzenteIT.DatabaseDocumentationTool.ViewModels
{
    using System.Collections.Generic;

    using AkzenteIT.DatabaseDocumentationTool.ViewModels.Base;

    using Microsoft.SqlServer.Management.Smo;

    /// <summary>
    /// The server view model.
    /// </summary>
    public class ServerViewModel : NodeViewModel
    {
        #region Fields

        /// <summary>
        /// The server.
        /// </summary>
        private readonly Server server;

        #endregion

        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="ServerViewModel"/> class.
        /// </summary>
        /// <param name="server">
        /// The server.
        /// </param>
        public ServerViewModel(Server server)
            : base(null)
        {
            this.server = server;
        }

        #endregion

        #region Public Properties

        /// <summary>
        /// Gets the name.
        /// </summary>
        public override string Name
        {
            get
            {
                return this.server.Name;
            }
        }

        #endregion

        #region Methods

        /// <summary>
        /// The load children.
        /// </summary>
        /// <returns>
        /// The System.Collections.Generic.IEnumerable`1[T -&gt; Tools.SqlServerDocGenerator.ViewModels.Base.NodeViewModel].
        /// </returns>
        protected override IEnumerable<NodeViewModel> LoadChildren()
        {
            foreach (Database database in this.server.Databases)
            {
                yield return new DatabaseViewModel(this, database);
            }
        }

        #endregion
    }
}